﻿/*-----------------------------------------------
// File: CopyBalance.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UI;
using ProtoBuf.Message;
using Dict.Blo;
using Dict.DataModel;

namespace Battle
{
    public class CopyBalance : BalanceBase
    {
        public GameObject starParent;
        public List<GameObject> stars;
        public List<GameObject> starsDi;
        public UILabel addCoinLabel;
        public UILabel addExpLabel;
        public UILabel addPointLabel;

        public BalanceExpBar expBar;
        public UIGrid dropGrid;

        public UILabel fragLabel;
        public UILabel evaluateLabel;

        public GameObject dropObjs;
        public GameObject lotteryObjs;

        List<GameObject> dropItems = new List<GameObject>();
        public List<DrawButton> drawButtons;

        public float ShowDrawOrItemDelay;

        public GameObject continueTipLabel;

        public GameObject winCondition;
        public GameObject loseCondition;
        public UILabel winConditionLabel;
        public UILabel loseConditionLabel;

        public GameObject lostTip;

        public GameObject rewardCoin;
        public GameObject rewardExp;
        public GameObject rewardPoint;

        public UILabel dropTip;
        #region 野外boss
        public GameObject coinIcon;
        public GameObject expIcon;
        public UILabel harmLabel;
        #endregion
        protected override void Refresh()
        {
            dropTip.text = TableTextBlo.GetText("copy_drop_award");
            int preLevel = StaticData.playerData.level;
            int preExp = (int)StaticData.playerData.exp;
            if (StaticData.curBattleData.battleType == BattleType.PVE)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCCopyFightEnd;
                if (msg.fightResult == 1)
                {
                    result = BalanceResult.Win;
                }
                else
                {
                    result = BalanceResult.Lose;
                }
                base.Refresh();
                dropObjs.SetActive(true);
                lotteryObjs.SetActive(false);
                starParent.SetActive(true);
                fragLabel.gameObject.SetActive(false);
                expBar.Init(preExp, preLevel, GetAwardThingNum(msg.gain, Dict.Config.TableConst.exp), (int)StaticData.playerData.exp, (int)StaticData.playerData.level);
                addCoinLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.gain, Dict.Config.TableConst.coin));
                addExpLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.gain, Dict.Config.TableConst.exp));
                winCondition.SetActive(false);
                loseCondition.SetActive(false);
                lostTip.SetActive(true);

                rewardCoin.SetActive(true);
                rewardExp.SetActive(true);
                rewardPoint.SetActive(false);

                if (result == BalanceResult.Win)
                {
                    expBar.Play();
                    addCoinLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addCoinLabel.GetComponent<TweenNumText>().Play();
                    addExpLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addExpLabel.GetComponent<TweenNumText>().Play();
                    StartCoroutine(GetResultItem(msg.gain));
                    StartCoroutine(SetStar(msg.star, 5, 3f, 0.3f));
                    foreach (var tweener in tweeners)
                    {
                        if (tweener != null && tweener.gameObject.activeSelf)
                        {
                            tweener.ResetToBeginning();
                            tweener.PlayForward();
                        }
                    }
                }
                else
                {
                    StartCoroutine(SetStar(msg.star, 5, 0f, 0f));
                    expBar.Over();
                    addCoinLabel.GetComponent<TweenNumText>().Over();
                    addExpLabel.GetComponent<TweenNumText>().Over();
                }
                continueTipLabel.SetActive(true);
            }
            else if (StaticData.curBattleData.battleType == BattleType.PLUNDER)
            {
                base.Refresh();
                var msg = GetResultMsg() as ProtoBuf.Message.SCFightTreasureStartResult;
                if (msg.isWin == 1)
                {
                    result = BalanceResult.Win;
                }
                else
                {
                    result = BalanceResult.Lose;
                }
                ShowPlunder();
                dropObjs.SetActive(false);
                lotteryObjs.SetActive(true);
                expBar.Init(preExp, preLevel, GetAwardThingNum(msg.get, Dict.Config.TableConst.exp), (int)StaticData.playerData.exp, (int)StaticData.playerData.level);
                addCoinLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.get, Dict.Config.TableConst.coin));
                addExpLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.get, Dict.Config.TableConst.exp));
                starParent.SetActive(false);
                winCondition.SetActive(false);
                loseCondition.SetActive(false);
                lostTip.SetActive(true);

                rewardCoin.SetActive(true);
                rewardExp.SetActive(true);
                rewardPoint.SetActive(false);
                if (result == BalanceResult.Win)
                {
                    expBar.Play();
                    addCoinLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addCoinLabel.GetComponent<TweenNumText>().Play();
                    addExpLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addExpLabel.GetComponent<TweenNumText>().Play();
                    foreach (var drawBtn in drawButtons)
                    {
                        drawBtn.Init(OnDrawButtonClick);
                    }

                    float tweenerTime = 0f;
                    UITweener lastTweener = null;
                    foreach (var tweener in tweeners)
                    {
                        if (tweener != null && tweener.gameObject.activeInHierarchy)
                        {
                            tweener.ResetToBeginning();
                            tweener.PlayForward();
                            if (tweenerTime <= tweener.duration)
                            {
                                tweenerTime = tweener.duration;
                                lastTweener = tweener;
                            }
                        }
                    }

                    lastTweener.SetOnFinished(delegate
                    {
                        totalMask.SetActive(false);

                        foreach (var drawBtn in drawButtons)
                        {
                            drawBtn.Holde();
                        }
                    });
                    mask.GetComponent<BoxCollider>().enabled = false;
                    continueTipLabel.SetActive(false);
                }
                else
                {
                    expBar.Over();
                    addCoinLabel.GetComponent<TweenNumText>().Over();
                    addExpLabel.GetComponent<TweenNumText>().Over();
                }
            }
            else if (StaticData.curBattleData.battleType == BattleType.ACTIVITY)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCDailyCopyFightEnd;
                result = (msg.isWin == 1) ? BalanceResult.Win : result = BalanceResult.Lose;

                base.Refresh();
                dropObjs.SetActive(true);
                lotteryObjs.SetActive(false);
                starParent.SetActive(true);
                fragLabel.gameObject.SetActive(false);
                winCondition.SetActive(false);
                loseCondition.SetActive(false);
                SetStar(msg.starNum, 5);
                lostTip.SetActive(true);

                rewardCoin.SetActive(true);
                rewardExp.SetActive(true);
                rewardPoint.SetActive(false);

                expBar.Init(preExp, preLevel, GetAwardThingNum(msg.get, Dict.Config.TableConst.exp), (int)StaticData.playerData.exp, (int)StaticData.playerData.level);
                addCoinLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.get, Dict.Config.TableConst.coin));
                addExpLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.get, Dict.Config.TableConst.exp));

                if (result == BalanceResult.Win)
                {
                    StartCoroutine(SetStar(msg.starNum, 5, 3, 0.3f));
                    expBar.Play();
                    addCoinLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addCoinLabel.GetComponent<TweenNumText>().Play();
                    addExpLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addExpLabel.GetComponent<TweenNumText>().Play();
                    StartCoroutine(GetResultItem(msg.get));
                    UI.ActivityCopyPage.Instance.BattleEnd(msg);
                    foreach (var tweener in tweeners)
                    {
                        if (tweener != null && tweener.gameObject.activeSelf)
                        {
                            tweener.ResetToBeginning();
                            tweener.PlayForward();
                        }
                    }
                }
                else
                {
                    StartCoroutine(SetStar(msg.starNum, 5, 0f, 0f));
                    expBar.Over();
                    addCoinLabel.GetComponent<TweenNumText>().Over();
                    addExpLabel.GetComponent<TweenNumText>().Over();
                }
            }
            else if (StaticData.curBattleData.battleType == BattleType.RUSH_BOSS)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCRushFightEnd;
                if (msg.result == 1)
                {
                    result = BalanceResult.Win;
                }
                else
                {
                    result = BalanceResult.Lose;
                }
                base.Refresh();
                dropObjs.SetActive(true);
                lotteryObjs.SetActive(false);
                starParent.SetActive(true);
                fragLabel.gameObject.SetActive(false);
                winCondition.SetActive(false);
                loseCondition.SetActive(false);
                lostTip.SetActive(true);
                expBar.Init(preExp, preLevel, 0, preExp, preLevel);
                rewardCoin.SetActive(true);
                rewardExp.SetActive(false);
                rewardPoint.SetActive(true);
                addCoinLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.resultObj, Dict.Config.TableConst.coin));
                addPointLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.resultObj, Dict.Config.TableConst.point));
                if (result == BalanceResult.Win)
                {
                    StartCoroutine(SetStar(msg.star, 3, 3f, 0.3f));
                    expBar.Over();
                    addCoinLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addCoinLabel.GetComponent<TweenNumText>().Play();
                    addPointLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addPointLabel.GetComponent<TweenNumText>().Play();
                    StartCoroutine(GetResultItem(msg.resultObj));

                    foreach (var tweener in tweeners)
                    {
                        if (tweener != null)
                        {
                            tweener.ResetToBeginning();
                            tweener.PlayForward();
                        }
                    }
                }
                else
                {
                    StartCoroutine(SetStar(msg.star, 3, 0, 0));
                    expBar.Over();
                    addCoinLabel.GetComponent<TweenNumText>().Over();
                    addPointLabel.GetComponent<TweenNumText>().Over();

                    loseConditionLabel.text = RushPage.ParseWinCondition(StaticData.curBattleData.rushWinKey, StaticData.curBattleData.rushWinValue);
                }
                continueTipLabel.SetActive(true);

            }
            else if (StaticData.curBattleData.battleType == BattleType.RUSH)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCRushFightEnd;
                if (msg.result == 1)
                {
                    result = BalanceResult.Win;
                }
                else
                {
                    result = BalanceResult.Lose;
                }
                base.Refresh();
                dropObjs.SetActive(false);
                lotteryObjs.SetActive(false);
                starParent.SetActive(true);
                fragLabel.gameObject.SetActive(false);
                winCondition.SetActive(true);
                loseCondition.SetActive(true);
                lostTip.SetActive(false);
                expBar.Init(preExp, preLevel, 0, preExp, preLevel);

                rewardCoin.SetActive(true);
                rewardExp.SetActive(false);
                rewardPoint.SetActive(true);

                addCoinLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.resultObj, Dict.Config.TableConst.coin));
                addPointLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.resultObj, Dict.Config.TableConst.point));



                if (result == BalanceResult.Win)
                {
                    StartCoroutine(SetStar(msg.star, 3, 3f, 0.3f));
                    expBar.Over();
                    addCoinLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addCoinLabel.GetComponent<TweenNumText>().Play();
                    addPointLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addPointLabel.GetComponent<TweenNumText>().Play();

                    winConditionLabel.text = RushPage.ParseWinCondition(StaticData.curBattleData.rushWinKey, StaticData.curBattleData.rushWinValue);

                    foreach (var tweener in tweeners)
                    {
                        if (tweener != null)
                        {
                            tweener.ResetToBeginning();
                            tweener.PlayForward();
                        }
                    }
                }
                else
                {
                    StartCoroutine(SetStar(msg.star, 3, 3f, 0.3f));
                    expBar.Over();
                    addCoinLabel.GetComponent<TweenNumText>().Over();
                    addPointLabel.GetComponent<TweenNumText>().Over();

                    loseConditionLabel.text = RushPage.ParseWinCondition(StaticData.curBattleData.rushWinKey, StaticData.curBattleData.rushWinValue);
                }
                continueTipLabel.SetActive(true);
            }
            else if(StaticData.curBattleData.battleType == BattleType.FIELD_PVE)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCSidePveFightEnd;
                if (msg.fightResult == 1)
                {
                    result = BalanceResult.Win;
                }
                else
                {
                    result = BalanceResult.Lose;
                }
                base.Refresh();
                dropObjs.SetActive(true);
                lotteryObjs.SetActive(false);
                starParent.SetActive(true);
                fragLabel.gameObject.SetActive(false);
                expBar.Init(preExp, preLevel, GetAwardThingNum(msg.getn, Dict.Config.TableConst.exp), (int)StaticData.playerData.exp, (int)StaticData.playerData.level);
                addCoinLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.getn, Dict.Config.TableConst.coin));
                addExpLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.getn, Dict.Config.TableConst.exp));
                winCondition.SetActive(false);
                loseCondition.SetActive(false);
                lostTip.SetActive(true);

                rewardCoin.SetActive(true);
                rewardExp.SetActive(true);
                rewardPoint.SetActive(false);

                if (result == BalanceResult.Win)
                {
                    expBar.Play();
                    addCoinLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addCoinLabel.GetComponent<TweenNumText>().Play();
                    addExpLabel.GetComponent<TweenNumText>().ResetToBeginning();
                    addExpLabel.GetComponent<TweenNumText>().Play();
                    StartCoroutine(GetResultItem(msg.getn));
                    StartCoroutine(SetStar(5, 5, 3f, 0.3f));
                    foreach (var tweener in tweeners)
                    {
                        if (tweener != null && tweener.gameObject.activeSelf)
                        {
                            tweener.ResetToBeginning();
                            tweener.PlayForward();
                        }
                    }
                }
                else
                {
                    StartCoroutine(SetStar(0, 5, 0f, 0f));
                    expBar.Over();
                    addCoinLabel.GetComponent<TweenNumText>().Over();
                    addExpLabel.GetComponent<TweenNumText>().Over();
                }
                continueTipLabel.SetActive(true);
            }

            else if (StaticData.curBattleData.battleType == BattleType.FIELD_BOSS)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCSidePveBossFightEnd;
                if (msg.fightResult == 1)
                {
                    result = BalanceResult.Win;
                    dropObjs.transform.SetParent(winBase.transform);
                }
                else
                {
                    result = BalanceResult.Lose;
                    dropObjs.transform.SetParent(loseBase.transform);
                }
                base.Refresh();
                dropObjs.SetActive(true);
                lotteryObjs.SetActive(false);
                starParent.SetActive(true);
                fragLabel.gameObject.SetActive(false);
                expBar.Init(preExp, preLevel, GetAwardThingNum(msg.get, Dict.Config.TableConst.exp), (int)StaticData.playerData.exp, (int)StaticData.playerData.level);
                addCoinLabel.GetComponent<TweenNumText>().Init(0,  msg.hurt );
                addExpLabel.GetComponent<TweenNumText>().Init(0, GetAwardThingNum(msg.get, Dict.Config.TableConst.exp));
                winCondition.SetActive(false);
                loseCondition.SetActive(false);

                lostTip.SetActive(false);

                rewardCoin.SetActive(true);
                rewardExp.SetActive(true);
                rewardPoint.SetActive(false);

                
                expBar.Play();
                addCoinLabel.GetComponent<TweenNumText>().ResetToBeginning();
                addCoinLabel.GetComponent<TweenNumText>().Play();
                addExpLabel.GetComponent<TweenNumText>().ResetToBeginning();
                addExpLabel.GetComponent<TweenNumText>().Play();
                StartCoroutine(GetResultItem(msg.get));
                StartCoroutine(SetStar(result == BalanceResult.Win ? 5 : 0, 5, 3f, 0.3f));
                foreach (var tweener in tweeners)
                {
                    if (tweener != null && tweener.gameObject.activeSelf)
                    {
                        tweener.ResetToBeginning();
                        tweener.PlayForward();
                    }
                }
                

                if(msg.code == 1)
                {
                    dropTip.text = TableTextBlo.GetText("field_kill_award");
                }
                else 
                {
                    dropTip.text = TableTextBlo.GetText("copy_drop_award_ex");
                }

                var kit = harmLabel.gameObject.GetComponent<TextKit>();
                if (kit != null)
                    kit.enabled = false;

                expIcon.SetActive(false);
                coinIcon.SetActive(false);
                harmLabel.text = TableTextBlo.GetText("make_damage");

                //addCoinLabel.text = msg.hurt+"";

                Debug.Log("[DEBUG] hurt !!! [" + msg.hurt+"]");

                continueTipLabel.SetActive(true);
            }

            isDrawButtonClicked = false;
        }

        private IEnumerator GetResultItem(ResultObject get)
        {
            if (get == null) yield break;

            addCoinLabel.text = GetAwardThingNum(get, Dict.Config.TableConst.coin).ToString();
            addExpLabel.text = GetAwardThingNum(get, Dict.Config.TableConst.exp).ToString();
            foreach (var info in get.wars)
            {
                var obj = GameObject.Instantiate(commonIconPrefab) as GameObject;
                obj.GetComponent<CommonIcon>().SetData(info.id, false);
                obj.transform.SetParent(dropGrid.transform);
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale = Vector3.one;
                obj.transform.localEulerAngles = Vector3.zero;
                dropItems.Add(obj);
            }
            foreach (var info in get.equips)
            {
                var obj = GameObject.Instantiate(commonIconPrefab) as GameObject;
                obj.GetComponent<CommonIcon>().SetData(info.equipId, false);
                obj.transform.SetParent(dropGrid.transform);
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale = Vector3.one;
                obj.transform.localEulerAngles = Vector3.zero;
                dropItems.Add(obj);
            }
            foreach (var info in get.treas)
            {
                var obj = GameObject.Instantiate(commonIconPrefab) as GameObject;
                obj.GetComponent<CommonIcon>().SetData(info.treasureId, false);
                obj.transform.SetParent(dropGrid.transform);
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale = Vector3.one;
                obj.transform.localEulerAngles = Vector3.zero;
                dropItems.Add(obj);
            }
            foreach (var info in get.simps)
            {
                if (info.id == (Dict.Config.TableConst.exp) || info.id == (Dict.Config.TableConst.coin) || info.id == (Dict.Config.TableConst.point))
                {
                    if(info.id == (Dict.Config.TableConst.coin) && StaticData.curBattleData.battleType != BattleType.FIELD_BOSS)
                        continue;
                }
                if (info.num == 0)
                    continue;
                var obj = GameObject.Instantiate(commonIconPrefab) as GameObject;
                obj.GetComponent<CommonIcon>().SetData(info.id, false, info.num);
                obj.transform.SetParent(dropGrid.transform);
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale = Vector3.one;
                obj.transform.localEulerAngles = Vector3.zero;
                dropItems.Add(obj);
            }
            foreach (var obj in dropItems)
            {
                obj.SetActive(false);
            }

            yield return new WaitForSeconds(ShowDrawOrItemDelay);
            foreach (var item in dropItems)
            {
                item.gameObject.SetActive(true);
                yield return new WaitForSeconds(0.5f);
            }


        }

        public override void OnTotalMaskClick()
        {
            base.OnTotalMaskClick();
            StopAllCoroutines();
            if (StaticData.curBattleData.battleType == BattleType.PVE ||
                StaticData.curBattleData.battleType == BattleType.ACTIVITY ||
                StaticData.curBattleData.battleType == BattleType.RUSH ||
                StaticData.curBattleData.battleType == BattleType.RUSH_BOSS ||
                StaticData.curBattleData.battleType == BattleType.FIELD_PVE ||
                StaticData.curBattleData.battleType == BattleType.FIELD_BOSS)
            {
                SetStarForce(starNum, starMaxNum);
            }
            else if (StaticData.curBattleData.battleType == BattleType.PLUNDER)
            {
                ShowPlunder();
            }
            foreach (var item in dropItems)
            {
                item.gameObject.SetActive(true);
            }
            addCoinLabel.GetComponent<TweenNumText>().Over();
            addExpLabel.GetComponent<TweenNumText>().Over();
            addPointLabel.GetComponent<TweenNumText>().Over();
            foreach (var drawBtn in drawButtons)
            {
                drawBtn.Holde();
            }
            expBar.Over();
        }

        public override void AddBalanceReward()
        {
            if (StaticData.curBattleData.battleType == BattleType.PVE)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCCopyFightEnd;
                if (msg.gain != null)
                {
                    StaticData.playerData.AddResultObj(msg.gain);
                }
            }
            else if (StaticData.curBattleData.battleType == BattleType.ACTIVITY)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCDailyCopyFightEnd;
                if (msg.get != null)
                {
                    StaticData.playerData.AddResultObj(msg.get);
                }
            }
            else if (StaticData.curBattleData.battleType == BattleType.RUSH || StaticData.curBattleData.battleType == BattleType.RUSH_BOSS)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCRushFightEnd;
                if (msg.resultObj != null)
                {
                    StaticData.playerData.AddResultObj(msg.resultObj);
                }
            }
            else if(StaticData.curBattleData.battleType == BattleType.FIELD_PVE)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCSidePveFightEnd;
                if (msg.getn != null)
                {
                    StaticData.playerData.AddResultObj(msg.getn);
                }
            }
            else if(StaticData.curBattleData.battleType == BattleType.FIELD_BOSS)
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCSidePveBossFightEnd;
                if (msg.get != null)
                {
                    StaticData.playerData.AddResultObj(msg.get);
                }
            }
            else
            {
                var msg = GetResultMsg() as ProtoBuf.Message.SCFightTreasureStartResult;
                if (msg.get != null)
                {
                    StaticData.playerData.AddResultObj(msg.get);
                }
            }
        }

        public override void Exit()
        {
            base.Exit();
            Hide();
            if (StaticData.curBattleData.battleType == BattleType.PVE)
            {
                ManagerController.Instance.BattleToCopy();
            }
            else if (
                StaticData.curBattleData.battleType == BattleType.RUSH || 
                StaticData.curBattleData.battleType== BattleType.RUSH_BOSS)
            {
                ManagerController.Instance.BattleToRush();
            }
            else if(StaticData.curBattleData.battleType == BattleType.FIELD_PVE ||
                StaticData.curBattleData.battleType == BattleType.FIELD_BOSS)
            {
                ManagerController.Instance.BattleToField();
            }
            else
            {
                ManagerController.Instance.BattleToRoom();
            }
            Destroy(gameObject);
        }

        protected void ShowPlunder()
        {
            stars[0].transform.parent.gameObject.SetActive(false);
            evaluateLabel.text = TableTextBlo.GetText("plunResult");
            //fragLabel.text = TableTextBlo.GetText("gain")+"";
            SCFightTreasureStartResult fte = (SCFightTreasureStartResult)GetResultMsg();
            if (fte.isGetFrag == 0)
            {
                fragLabel.text = TableTextBlo.GetText("notGetTreaFragWhite");
            }
            else
            {
                TableFrag tf = DictFragBlo.GetTableFrag(StaticData.curBattleData.targetFrag);
                TableTreasure tt = DictTreasureBlo.GetTableTreasure(tf.target);
                string n = "[" + FontColor.Get(tt.quality) + "]" + CommonMethod.GetFragName(StaticData.curBattleData.targetFrag) + "[-]";
                fragLabel.text = "[000000]" + TableTextBlo.GetText("gain") + "[-]" + n;
            }
        }


        int starNum;
        int starMaxNum;
        IEnumerator SetStar(int num, int maxNum, float start, float interval)
        {
            starNum = num;
            starMaxNum = maxNum;
            var showStars = SetStar(num, maxNum);
            yield return new WaitForSeconds(start);
            foreach (var star in showStars)
            {
                star.SetActive(true);
                yield return new WaitForSeconds(interval); 
            }
        }

        void SetStarForce(int num, int maxNum)
        {
            starNum = num;
            starMaxNum = maxNum;
            var showStars = SetStar(num, maxNum);
            foreach (var star in showStars)
            {
                star.SetActive(false);
                star.transform.parent.GetComponent<UISprite>().spriteName = "UI_jiesuan_star_01";
            }
        }

        protected List<GameObject> SetStar(int num, int maxNum)
        {
            List<GameObject> showStars = new List<GameObject>();
            fragLabel.text = "";
            evaluateLabel.text = TableTextBlo.GetText("copy_pass_evaluate");
            starParent.SetActive(true);
            if (maxNum > 5)
            {
                maxNum = 5;
            }
            if (num > maxNum)
            {
                num = maxNum;
            }
            else if (num < 0)
            {
                num = 0;
            }
            int i = 0;
            for (; i < maxNum; ++i)
            {
                if (i < num)
                {
                    showStars.Add(stars[i]);
                }
                starsDi[i].SetActive(true);
                stars[i].SetActive(false);
                starsDi[i].GetComponent<UISprite>().spriteName = "UI_jiesuan_star_01_di";
            }
            for (; i < 5; ++i)
            {
                starsDi[i].SetActive(false);
                stars[i].SetActive(false);
                starsDi[i].GetComponent<UISprite>().spriteName = "UI_jiesuan_star_01_di";
            }

            return showStars;

        }

        bool isDrawButtonClicked = false;

        public void OnDrawButtonClick(GameObject obj)
        {
            if (isDrawButtonClicked)
            {
                return;
            }
            var msg = StaticData.lastBattleEndMsg as ProtoBuf.Message.SCFightTreasureStartResult;
            var clickBtn = obj.GetComponent<DrawButton>();
            clickBtn.PlayTurnEffect();
            clickBtn.SetIcon(msg.reward, true);
            int index = 0;
            foreach (var btn in drawButtons)
            {
                if (btn == clickBtn)
                    continue;
                index++;
                if (index == 1)
                {
                    btn.SetIcon(msg.rewardFake1, false, 0.5f);
                }
                else
                {
                    btn.SetIcon(msg.rewardFake2, false, 0.5f);
                }
            }
            mask.GetComponent<BoxCollider>().enabled = true;
            continueTipLabel.SetActive(true);
            isDrawButtonClicked = true;

        }
    }

}
